
#include "undoredo.h"
#include "euleroperator.h"
#include <iostream>



bool 
UndoRedo::hasUndo()
{
  if( m_undocommands.size() > 0 )
    return true;
  return false;
}


bool 
UndoRedo::hasRedo()
{
  if( m_redocommands.size() > 0 )
    return true;
  return false;
}

void 
UndoRedo::insertCommand(EulerOperator* _command)
{
  //std::cout << "\nUndoRedo::insertCommand() \n";
  m_undocommands.push(_command);
  while( !m_redocommands.empty() )
    m_redocommands.pop();
}


void 
UndoRedo::undo(int levels)
{
  for (int i = 1; i <= levels; i++)
  {
    if( !m_undocommands.empty() )
    {
      EulerOperator* command = m_undocommands.top();
      command->unExecute();
      m_undocommands.pop();
      m_redocommands.push(command);
    }
  }
}


void 
UndoRedo::redo(int levels)
{
  for (int i = 1; i <= levels; i++)
  {
    if( !m_redocommands.empty() )
    {
      EulerOperator* command = m_redocommands.top();
      command->execute();
      m_redocommands.pop();
      m_undocommands.push(command);
    }
  }
}

